<template>
    <div>
<h1>病房信息添加</h1>
<table class="table">
    <tbody>
        <tr>
            <td>房号</td>
            <td>
                <input type="text" v-model="da.fangHao">
            </td>
        </tr>

          <tr>
            <td>科室</td>
            <td>
            <select v-model="da.ksId">
                <option  :value="0">请选择</option>
                <option v-for="a in ba" :value="a.kId">{{ a.ksName }}</option>
            </select>
        </td>
        </tr>


          <tr>
            <td>床位数量</td>
            <td>
                
                <input type="number" v-model="da.shuLiang">
            </td>
        </tr>

          <tr>
            <td>空闲床数量</td>
            <td>
                <input type="number" v-model="da.kong">
            </td>
        </tr>

          <tr>
            <td></td>
            <td>
                <input type="button" value="添加" @click="add">
            </td>
        </tr>
    </tbody>
</table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
const uc=useRouter()

const da=ref({
  "bingId": 0,
  "fangHao": "",
  "ksId": 0,
  "shuLiang": null,
  "ztId": 1,
  "kong": null,
  "fangCreateTime": "2025-05-19T05:23:15.494Z"
})

const add=()=>{

if(da.value.fangHao==""||da.value.kong==null||da.value.shuLiang==null){
    alert("不能为空");
    return
}

if(da.value.fangHao.length>6){
    alert("病房名称不能超过6个字符");
    return
}

if(da.value.kong> da.value.shuLiang){
    alert("空闲床数量不能超过床位总数量");
     return
}

    axios.post("/api/Fang/AddFang",da.value).then(res=>{
        if(res.data>0){
            alert("添加成功")
            uc.push({path:"/showbf"})
        }else{
             alert("添加失败")
        }
    })
}



onMounted(()=>{
    bang()
})

//绑定的m
const ba=ref([{
    "kId": 0,
    "ksName": "",
    "ksCount": 0,
    "ksMiaoShu": "",
    "ksCreateTime": "2025-05-19T11:29:32.2299346",
    "ksIsDel": false
  }])

  //绑定
  const bang=()=>{
    axios.get("/api/YiS/BangKs").then(res=>{
        ba.value=res.data;
    })
  }
</script>

<style scoped>

</style>